Skip to content

Add lookupOpenMiningRoundByNumber#5060

Open
adetokunbo wants to merge 3 commits intodfordivam/cip-104-sv-app-rewards-feature-branchfrom
adetokunbo/cip-104-add-lookup-open-mining-round-by-number
Open

Add lookupOpenMiningRoundByNumber#5060
adetokunbo wants to merge 3 commits intodfordivam/cip-104-sv-app-rewards-feature-branchfrom
adetokunbo/cip-104-add-lookup-open-mining-round-by-number

Conversation

@adetokunbo
Copy link
Copy Markdown
Contributor

Adds this to the SV app rewards branch since it's only going to be used by this branch until it is merged into main

This change anticipates the use of this function on this branch after the computation branch is merged into main, and then merged into here.

Pull Request Checklist

Cluster Testing

  • If a cluster test is required, comment /cluster_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a hard-migration test is required (from the latest release), comment /hdm_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.
  • If a logical synchronizer upgrade test is required (from canton-3.5), comment /lsu_test on this PR to request it, and ping someone with access to the DA-internal system to approve it.

PR Guidelines

  • Include any change that might be observable by our partners or affect their deployment in the release notes.
  • Specify fixed issues with Fixes #n, and mention issues worked on using #n
  • Include a screenshot for frontend-related PRs - see README or use your favorite screenshot tool

Merge Guidelines

  • Make the git commit message look sensible when squash-merging on GitHub (most likely: just copy your PR description).

@adetokunbo adetokunbo added this to the Traffic-Based App Rewards milestone Apr 16, 2026
@adetokunbo adetokunbo self-assigned this Apr 16, 2026
@adetokunbo adetokunbo force-pushed the adetokunbo/cip-104-add-lookup-open-mining-round-by-number branch from 73d2991 to 470a2d3 Compare April 16, 2026 07:53
@dfordivam dfordivam force-pushed the dfordivam/cip-104-sv-app-rewards branch 2 times, most recently from d8096d6 to 54a0a93 Compare April 17, 2026 01:47
): Future[Seq[ContractWithState[OpenMiningRound.ContractId, OpenMiningRound]]] =
tcsStore.listAllContractsAsOf(OpenMiningRound.COMPANION, asOf)

override def lookupOpenMiningRoundByNumber(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should at least make use of acsStore.waitUntilAcsIngested.
It may be even better to wait if the round being looked up has not been ingested yet? we could compare max round in active table to assess that, and use acsStore.waitUntilRecordTimeReached?

If doing wait here is not possible, then it may be better to return something other than None?

If None is an acceptable response in such cases, (because the trigger would try again after a while?), then it should be made clear in comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario would happen when scan has restarted and is catching up, The CalculateRewardsV2 would come from ScanStore which may be ahead of DbScanRewardsReferenceStore.
Currently it seems that the only thing the trigger would do when receiving None is retry?
it won't give up right?
so doing retry at the trigger level may be fine

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely add acsStore.waitUntilAcsIngested, the call might throw an exception otherwise ("using a storeId before it was initialized").

IMO it's fine to have ACS stores return data for the current state of the store (i.e., return None if the mining round has not been ingested yet), and let callers handle the fact that different stores might be lagging behind by arbitrary amounts of time.

As for triggers, after retrieveTasks() returns a task, the trigger will retry the task a few times, but if it keeps failing the trigger will eventually give up and retrieve the next task.

As long as you make sure retrieveTasks() is implemented such that it properly resumes from the persisted state, you should be fine.

I would still make sure we are not failing tasks just because some store is not caught up. Tasks that fail even after retries produce log warnings, and we alert on those in production. So either have retrieveTasks() only return tasks that have a reasonable chance of succeeding, or successfully complete a task if some data is missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: Thanks for all the feedback here, I've added waitUntilAcsIngested as recommended

): Future[Seq[ContractWithState[OpenMiningRound.ContractId, OpenMiningRound]]] =
tcsStore.listAllContractsAsOf(OpenMiningRound.COMPANION, asOf)

override def lookupOpenMiningRoundByNumber(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely add acsStore.waitUntilAcsIngested, the call might throw an exception otherwise ("using a storeId before it was initialized").

IMO it's fine to have ACS stores return data for the current state of the store (i.e., return None if the mining round has not been ingested yet), and let callers handle the fact that different stores might be lagging behind by arbitrary amounts of time.

As for triggers, after retrieveTasks() returns a task, the trigger will retry the task a few times, but if it keeps failing the trigger will eventually give up and retrieve the next task.

As long as you make sure retrieveTasks() is implemented such that it properly resumes from the persisted state, you should be fine.

I would still make sure we are not failing tasks just because some store is not caught up. Tasks that fail even after retries produce log warnings, and we alert on those in production. So either have retrieveTasks() only return tasks that have a reasonable chance of succeeding, or successfully complete a task if some data is missing.


create index scan_rewards_reference_store_archived_round
on scan_rewards_reference_store_archived (store_id, migration_id, round)
where round is not null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always nervous when we're creating indexes on non-empty tables in flyway migrations, because migrations are blocking application startup. AFAICT, this table should be sufficiently small that the index creation completes in a second, so it's fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thanks!

@dfordivam dfordivam force-pushed the dfordivam/cip-104-sv-app-rewards branch 2 times, most recently from 8f7f2d1 to 2c49978 Compare April 20, 2026 03:13
@adetokunbo adetokunbo force-pushed the adetokunbo/cip-104-add-lookup-open-mining-round-by-number branch from 470a2d3 to 4b8a1b0 Compare April 20, 2026 04:01
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
Signed-off-by: Tim Emiola <adetokunbo@emio.la>
@adetokunbo adetokunbo changed the base branch from dfordivam/cip-104-sv-app-rewards to dfordivam/cip-104-sv-app-rewards-feature-branch April 20, 2026 08:58
@adetokunbo adetokunbo force-pushed the adetokunbo/cip-104-add-lookup-open-mining-round-by-number branch from 2da39fa to 9a37516 Compare April 20, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants